package com.hp.team.bookstore.model.catalog;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "CATEGORY")
public class Category extends CatalogItem {
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "CATALOG_ID", nullable = false)
	private Catalog parentCatalog;
	
	@ManyToOne(cascade={CascadeType.ALL})
    @JoinColumn(name="CATEGORY_ID")
    private Category parentCategory;
	
	@OneToMany(mappedBy = "parentCategory")
    private Set<Category> childCategories = new HashSet<Category>();
	
	@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy="parentCategories")
	private Set<Product> products;

	public Catalog getParentCatalog() {
		return parentCatalog;
	}

	public Category getParentCategory() {
		return parentCategory;
	}

	public Set<Category> getChildCategories() {
		return childCategories;
	}

	public Set<Product> getProducts() {
		return products;
	}

	public void setParentCatalog(Catalog parentCatalog) {
		this.parentCatalog = parentCatalog;
	}

	public void setParentCategory(Category parentCategory) {
		this.parentCategory = parentCategory;
	}

	public void setChildCategories(Set<Category> childCategories) {
		this.childCategories = childCategories;
	}

	public void setProducts(Set<Product> products) {
		this.products = products;
	}

}
